package com.xyz.gate.service;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * 校验密码是否正确
 */
@Service
public class UserService {

    private static HashMap<String,String> userDataBase = new HashMap<>();

    static {
        userDataBase.put("a","123");
        userDataBase.put("b","123");
    }

    public boolean checkPwd(JSONObject info) {
        if(info.isEmpty()) {
            return false;
        }
        try {
            String pwd = userDataBase.get(info.getString("userName"));
            if(StrUtil.isEmpty(pwd)) {
                return false;
            }
            return StrUtil.equals(pwd,info.getString("passwd"));
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }

}
